#include "widget.h"
#include "ui_widget.h"
#include<QTextEdit>
#include<QDebug>
#include<QTextCursor>
#include<fstream>
#include<QDateTime>
#include<QRect>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //textEdit的使用
    ui->textEdit->setPlaceholderText("请输入你们喜欢的语句");


    //chomBox的使用,从文件中读取
    std::ifstream fruit;
    fruit.open("f:/fooded/fruit.txt");
    std::string fruit_s;
    while(std::getline(fruit,fruit_s))
    {
        ui->comboBox_fruit->addItem(QString::fromStdString(fruit_s));
    }
    fruit.close();

    std::ifstream food;
    food.open("f:/fooded/food.txt");
    std::string food_s;
    while(std::getline(food,food_s))
    {
        ui->comboBox_food->addItem(QString::fromStdString(food_s));
    }
    food.close();

    std::ifstream drink;
    drink.open("f:/fooded/drink.txt");
    std::string drink_s;
    while(std::getline(drink,drink_s))
    {
        ui->comboBox_drink->addItem(QString::fromStdString(drink_s));
    }
    drink.close();


    //spinBox的使用
    ui->spinBox_fruit->setValue(1);
    ui->spinBox_fruit->setRange(1,10);
    ui->spinBox_food->setValue(1);
    ui->spinBox_food->setRange(1,10);
    ui->spinBox_drink->setValue(1);
    ui->spinBox_drink->setRange(1,10);

    ui->verticalSlider_vertical->setMinimum(500);
    ui->verticalSlider_vertical->setMaximum(1500);
    ui->verticalSlider_vertical->setValue(800);
    ui->verticalSlider_vertical->setSingleStep(50);

    ui->horizontalSlider_level->setMinimum(500);
    ui->horizontalSlider_level->setMaximum(1500);
    ui->horizontalSlider_level->setValue(600);
    ui->horizontalSlider_level->setSingleStep(50);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_textEdit_textChanged()
{
    QString text=ui->textEdit->toPlainText();
    ui->label_show->setText(text);
}

void Widget::on_textEdit_selectionChanged()
{
    const QTextCursor& cursor=ui->textEdit->textCursor();
    qDebug()<<"selectText: "<<cursor.selectedText();

}

void Widget::on_textEdit_cursorPositionChanged()
{
    const QTextCursor& cursor=ui->textEdit->textCursor();
    qDebug()<<"cursorPosition: "<<cursor.position();
}

void Widget::on_textEdit_redoAvailable(bool b)
{
    qDebug()<<"redo: "<<b;
}

void Widget::on_textEdit_undoAvailable(bool b)
{
    qDebug()<<"undo: "<<b;
}

void Widget::on_textEdit_copyAvailable(bool b)
{
    qDebug()<<"copy: "<<b;
}

void Widget::on_pushButton_clicked()
{
   qDebug()<<"水果："<<ui->comboBox_fruit->currentText()<<" "<<ui->spinBox_fruit->value()
          <<",主食："<<ui->comboBox_food->currentText()<<" "<<ui->spinBox_food->value()
         <<",奶茶： "<<ui->comboBox_drink->currentText()<<" "<<ui->spinBox_drink->value();
}

void Widget::on_pushButton_count_clicked()
{
    QDateTime Old=ui->dateTimeEdit->dateTime();
    QDateTime New=ui->dateTimeEdit_2->dateTime();

    int seconds=New.secsTo(Old);
    int day=(seconds/3600)/24;
    int hour=(seconds/3600)%24;

    QString content="爱你已经持续了"+QString::number(day)+" 天零 "+QString::number(hour)+" 个小时";

    ui->label_show->setText(content);
}


void Widget::on_dial_valueChanged(int value)
{
    ui->label_6->setText("不透明度"+QString::number(value));
    this->setWindowOpacity((double)value/100);
}

void Widget::on_horizontalSlider_level_valueChanged(int value)
{
    QRect rect=this->geometry();
    this->setGeometry(rect.x(),rect,y(),value,rect.height());
}

void Widget::on_verticalSlider_vertical_valueChanged(int value)
{
    QRect rect=this->geometry();
    this->setGeometry(rect.x(),rect,y(),rect.width(),value);
}
